package com.lc.railway.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.request.RequestOptions;
import com.lc.railway.R;
import com.lc.railway.http.glide.GlideApp;
import com.lc.railway.http.response.IndexnBean;
import com.lc.railway.other.IntentKey;
import com.lc.railway.viewholder.ImageHolder;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * 自定义布局，图片
 */
public class ImageAdapter extends BannerAdapter<IndexnBean.IsShowBean, ImageHolder> {
private Context context;
    public ImageAdapter(Context context,List<IndexnBean.IsShowBean> mDatas) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(mDatas);
        this.context=context;
    }

    //更新数据
    public void updateData(List<IndexnBean.IsShowBean> data) {
        //这里的代码自己发挥，比如如下的写法等等
        mDatas.clear();
        mDatas.addAll(data);
        notifyDataSetChanged();
    }


    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    @Override
    public ImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
//
        return new ImageHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.banner_image_title, parent, false));
    }

    @Override
    public void onBindView(ImageHolder holder, IndexnBean.IsShowBean data, int position, int size) {
        holder.title.setText(data.getTitle());
        GlideApp.with(context).load(IntentKey.IMAGE+data.getPicurl()).apply(new RequestOptions().placeholder(R.drawable.image11).error(R.drawable.image11)).into(((ImageView) holder.imageView));

    }

}
